package mongo.mongodb;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.yxk.mongodb.User;
import org.yxk.mongodb.UserDao;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:bean.xml"})
public class MongoTest2 {
	@Resource
	 private   UserDao userDaoImpl;  
	    private static String collectionName="users";  
	   
	        @Test   
	        public void testAdd() throws Exception{  
	            //添加一百个user  
	            for(int i=0;i<100;i++){  
	                User user =new User();  
	                user.setId(""+i);  
	                user.setAge(i);  
	                user.setName("zcy"+i);  
	                user.setPassword("zcy"+i);  
	                userDaoImpl.insert(user,collectionName);  
	            }  
	            Map<String,Object> params=new HashMap<String,Object>();  
	            params.put("maxAge", 50);  
	            List<User> list=userDaoImpl.findAll(params,collectionName);  
	            System.out.println("user.count()=="+list.size());  
	        }  
	        @Test
			public void testQuery() throws Exception {
	        	Map<String, Object> map= new HashMap<>();
	        	map.put("name", "zcy3");
	        	map.put("password", "zcy3");
	        	map.put("age", 3);
	        	User user = userDaoImpl.findOne(map, collectionName);
	        	System.out.println(user);
			}
}
